using System;
using System.Reflection;
using Velocity4Net.Runtime.Logging;

namespace Velocity4Net.Runtime.Parse.AST
{
    /**
     * Abstract class that is used to execute an arbitrary
     * method that is in introspected. This is the superclass
     * for the GetExecutor and PropertyExecutor.
     *
     * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
     * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
     * @version $Id: AbstractExecutor.java 685685 2008-08-13 21:43:27Z nbubna $
     */
    public abstract class AbstractExecutor
    {
        /** */
        protected Log log = null;

        /**
         * Method to be executed.
         */
        private MethodInfo method = null;

        /**
         * Execute method against context.
         * @param o
         * @return The resulting object.
         * @throws IllegalAccessException
         * @throws InvocationTargetException
         */
        public abstract Object Execute(Object o);
        /**
         * Tell whether the executor is alive by looking
         * at the value of the method.
         *
         * @return True if executor is alive.
         */
        public bool isAlive()
        {
            return (method != null);
        }

        /**
         * @return The current method.
         */
        public MethodInfo getMethod()
        {
            return method;
        }

        /**
         * @param method
         * @since 1.5
         */
        protected void setMethod(MethodInfo method)
        {
            this.method = method;
        }
    }
}
